package top.dbpanda.cmsjpa.learn.nio.remote;

import lombok.AllArgsConstructor;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author 20018954
 */
@AllArgsConstructor
public class SendFile implements Runnable {
    private Socket socket;

    @Override
    public void run() {
        try {
            System.out.printf("连接成功");
            //out 用于将内存形式的文件，远程发送到客户端
            OutputStream outputStream = socket.getOutputStream();
            File file = new File("");
            //fileIn 用于将硬盘文件读入内存
            FileInputStream fileInputStream = new FileInputStream(file);
            byte[] bytes = new byte[64];
            int len = -1;
            while ((len = fileInputStream.read(bytes)) != -1) {
                outputStream.write(bytes, 0, len);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {

        }

    }
}
